﻿#include "common.h"
#include "../../include/itframework.h"
#include "../../include/itlogger.h"

extern "C" __declspec(dllexport) ITCommon* GetInstance()
{
    return dynamic_cast<ITCommon*>(Common::GetInstance());
}

Common::Common()
{
    qDebug() << "Common::Common()";
}

Common::~Common()
{
    qDebug() << "Common::~Common()";
}

void Common::SetFramework(ITFramework *pFrm)
{
    m_pFramework = pFrm;
    m_pFramework->GetLogger(&m_pLogger);
}

void Common::copystru8(QString source, char *dest, int ndestLen)
{
    int nsourceLen = qstrlen(source.toUtf8().data());
    memcpy(dest, source.toUtf8().data(), ndestLen-1);
    if(nsourceLen > ndestLen-1)
    {
        m_szLog = QString("copystru8 warning destLen=%1 sourceString=%2...")
                .arg(ndestLen).arg(source.left(8));
        m_pLogger->WriteLog(m_szLog.toUtf8().data());
    }
}

void Common::copystru8(char *source, char *dest, int ndestLen)
{
    int nsourceLen = qstrlen(source);
    memcpy(dest, source, ndestLen-1);
    if(nsourceLen > ndestLen-1)
    {
        m_szLog = QString("copystru8 warning destLen=%1 sourceChar=%2...")
                .arg(ndestLen).arg(QString::fromUtf8(source).left(8));
        m_pLogger->WriteLog(m_szLog.toUtf8().data());
    }
}
